import React, { Component } from 'react';
import { observer, inject } from 'mobx-react';
import { toJS } from 'mobx';
import { withRouter, Route } from 'react-router-dom';
import FieldList from '../FieldList';
import ContacterListForCard from '../ContacterList';
import PlanListForCard from '../PlanList';
import CardHearder from '../../public/CardHearder';
import { Card, WhiteSpace, Icon, ActionSheet, Modal, ActivityIndicator, Result, Tools, PullToRefresh, Bubble } from 'weaver-mobile';
import { BrowserHrm, RouteLayout, TabPage, ListViewPage, MapPage , Share } from 'weaver-mobile-page';
import CustomerMap from '../CustomerMap';
import ContacterForm from '../../form/ContacterForm';
import ContacterList from '../../list/ContacterList';
import ChanceForm from '../../form/ChanceForm';
import ContacterCard from '../../card/Contacter';
import ChanceCard from '../../card/Chance';
import CommerceCard from '../../card/Commerce';
import CustomerVisit from '../../card/CustomerVisit';
import CustomerShareList from '../../list/CustomerShareList';
import CustomerCardStore from '../../../stores/card/CustomerCardStore';
import ChangePosition from '../../card/CustomerMap/changePosition'
import ContactList from '../../list/ContactList';
import WorkplanListSingle from '../../list/WorkplanListSingle';
import CustomerViewAndEdit from '../../form/CustomerViewAndEdit';
import CrmResult from '../CrmResult';
import NoRight from '../../public/NoRight';

const Edit = MapPage.Edit;
const alert = Modal.alert;
const isIPhone = new RegExp('\\biPhone\\b|\\biPod\\b', 'i').test(window.navigator.userAgent);
let wrapProps;
if (isIPhone) {
  wrapProps = {
    onTouchStart: e => e.preventDefault(),
  };
}
const getLabel = Tools.getLabel;
// @inject('customerCardStore')
@withRouter
@observer
export default class CustomerCard extends Component {
  constructor(props) {
    super(props);
    this.state = {
      store: new CustomerCardStore(),
      span: [7, 1],
      curContacterId: "",
      curChanceId: "",
      curWorkplanId: "",
      showAddContact: false
    }
  }

  componentWillMount() {
    // const {customerCardStore,match,params} = this.props;
    // console.log(this.props)
    const { match, params, location } = this.props;
    let ps = params ? params : match.params;
    const store = this.state.store;
    if (location.search) {
      ps = { ...ps, ...Tools.getFrameParams() };
    }
    let psnew = this.dealWithParam(ps);
    store.doNew(this, psnew);
    store.getUserCurrentPosition();
  }

  dealWithParam = (ps)=>{
    let psbak = {};
    if(ps.id.lastIndexOf("moduleid")>-1 || ps.id.lastIndexOf("isfromchatshare") > -1){
      let strs= new Array(); 
      strs=ps.id.split("&"); 
      psbak.id = strs[0];
      for (let i=1;i<strs.length ;i++ ) { 
        let param= new Array(); 
        param=strs[i].split("=");  
        if(param.length >=2){
          psbak[param[0]] = param[1];
        }          
      } 
    }else{
       if("id" in ps){
        psbak.id = ps.id;
      }
      
    }
    return psbak;
  
  }

  componentDidMount() {
    // const {customerCardStore} = this.props;
    const store = this.state.store;
    store.doInit();
  }

  componentWillUnmount() {
    // const { customerCardStore } = this.props;
    const store = this.state.store;
    store.doClear();
  }

  componentWillReceiveProps(nextProps) {
    const pn = this.props.location.pathname;
    //新建日程页面回退,刷新当前页面
    if (pn.indexOf("workplanCreateLayout") != -1 || pn.indexOf("workplanViewLayout") != -1) {
      const store = this.state.store;
      store.doInit();
    }
  }

  render() {
    // const store = this.props.customerCardStore;
    const store = this.state.store;
    const { initResponsed, initSuccessed, initFailedMsg } = store;
    if (initResponsed) {
      if (initSuccessed) {
        const { span, curContacterId, curChanceId, curWorkplanId, showAddContact } = this.state;
        const { tabs, lat1, lng1, tabPage, refreshing, canEdit, canView, customerId, fieldItems, addressItem, contacterItems, contacterCount, customerName, customerManager, customerAddress,
          customerConcerned, managerBrowser, customerMapLayout, createChanceLayout, createContacterLayout, contacterListLayout, contacterCardLayout,
          commerceCardLayout, signInOutLayout, changeLocalLayout, shareListLayout, chanceListStore, contactListStore, crmDetailAndEditLayout, chanceCardLayout, getMap, lan, planItems,
          planCount, workplanCreateLayout, workplanViewLayout, workplanListLayout, hasPosition, getUserPosition, isManager, userCurrentlat, userCurrentlng, userCurrentAddress, customerManagerId ,
          canShare,shareCustomerLayout,shareStore,userId,onlyView} = store;
        const tabProps = {
          page: tabPage,
          swipeable: true,
          onChange: (tab) => {
            store.tabChange(tab.key);
          },
        };
        // console.log(lat1, lng1)
        if (canView) {
          return (
            <div className="crm-card-base">
              <CardHearder
                title1={customerName}
                // title2={customerManager}
                title2={`<div onclick="javascript:window.openLink.openHrm(${customerManagerId});">${customerManager}</div>`}
                title3={customerAddress}
                showConcerned={!onlyView?true:false}
                showMore={false}
                concerned={customerConcerned}
                concernedClick={this.concernedClick.bind(this)}
                moreClick={this.moreClick.bind(this)}
                lat={lat1}
                lon={lng1}
                canEdit={canEdit}
                iscrmcard={true}
                userCurrentlat={userCurrentlat}
                userCurrentlng={userCurrentlng}
                userCurrentAddress={userCurrentAddress}
                changePosition={() => { this.iconClick("address"); this.setState({ headLeadClick: true }) }}
                onRef={(e) => { this.cardheadRef = e }}
              />
              <div className="crm-card-content">
                <TabPage
                  span={span}
                  tabs={tabs}
                  tabProps={tabProps}
                  btns={!onlyView?[<Icon type="ellipsis" onClick={this.moreClick.bind(this)} />]:[]}
                />
                <WhiteSpace />
                {
                  tabPage == "info" && (
                    <div className="crm-card-main">
                      <PullToRefresh
                        damping={60}
                        style={{
                          height: "100%",
                          overflow: 'auto',
                        }}
                        direction={'down'}
                        refreshing={refreshing}
                        onRefresh={() => {
                          store.doInit();
                        }}
                      >
                        <Card full>
                          <Card.Header
                            title={<span style={{ marginLeft: "5px", whiteSpace: "nowrap" }}>{getLabel('24893', '基础信息')}</span>}
                            extra={<span></span>}
                          >
                          </Card.Header>
                          <Card.Body>
                            <FieldList fieldItems={fieldItems} iconClick={this.iconClick.bind(this)} contentClick={this.contentClick.bind(this)} />
                            <div className="crm-field-item-bottom"></div>
                          </Card.Body>
                          <Card.Footer content={
                            <div className="crm-card-footer" onClick={() => {
                              this.props.history.push(crmDetailAndEditLayout.path);
                            }}>
                              <div>{getLabel('1293', '查看详细信息')}</div>
                              <div className="crm-field-item-operate"><Icon type={"right"} /></div>
                            </div>
                          } />
                        </Card>
                        <WhiteSpace />
                        <Card full>
                          <Card.Header
                            title={<span style={{ marginLeft: "5px", whiteSpace: "nowrap" }}>{getLabel('572', '联系人')}</span>}
                            extra={
                              (canEdit && <span><i className='crm-card-bar-icon icon-crm icon-crm-add' onClick={
                                () => {
                                  this.props.history.push(createContacterLayout.path);
                                }
                              } /></span>)
                            }
                          >
                          </Card.Header>
                          {toJS(contacterItems).length > 0 && <Card.Body>
                            <ContacterListForCard contacterItems={contacterItems} onContacterClick={this.onContacterClick.bind(this)} />
                          </Card.Body>
                          }
                          <Card.Footer content={
                            <div className="crm-card-footer" onClick={() => {
                              this.props.history.push(contacterListLayout.path);
                            }}>
                              <div>{getLabel('390916', "查看全部联系人")}&nbsp;&nbsp;|&nbsp;&nbsp;{contacterCount}</div>
                              <div className="crm-field-item-operate"><Icon type={"right"} /></div>
                            </div>
                          } />
                        </Card>
                        <WhiteSpace />
                        {!onlyView&&<Card full>
                          <Card.Header
                            title={<span style={{ marginLeft: "5px", whiteSpace: "nowrap" }}>{getLabel('16402', "联系计划")}</span>}
                            extra={
                              <span><i className='crm-card-bar-icon icon-crm icon-crm-add' onClick={
                                () => {
                                  this.props.history.push(workplanCreateLayout.path);
                                }
                              } /></span>
                            }
                          >
                          </Card.Header>
                          {toJS(planItems).length > 0 && <Card.Body>
                            <PlanListForCard cardStore={store} planItems={planItems} onItemClick={this.onPlanItemClick.bind(this)} />
                          </Card.Body>
                          }
                          <Card.Footer content={
                            <div className="crm-card-footer" onClick={() => {
                              this.props.history.push(workplanListLayout.path);
                            }}>
                              <div>{getLabel('367', "查看") + getLabel('332', "全部") + getLabel('407', "计划")}&nbsp;&nbsp;|&nbsp;&nbsp;{planCount}</div>
                              <div className="crm-field-item-operate"><Icon type={"right"} /></div>
                            </div>
                          } />
                        </Card>}
                        <WhiteSpace />
                        <Card full>
                          <Card.Header
                            title={<span style={{ marginLeft: "5px", whiteSpace: "nowrap" }}>{getLabel('500932', "位置信息")}</span>}
                          >
                          </Card.Header>
                          <Card.Body>
                            <FieldList fieldItems={addressItem} iconClick={this.iconClick.bind(this)} />
                            <div className="crm-field-item-bottom"></div>
                          </Card.Body>
                          <Card.Footer content={
                            <div className="crm-card-footer" onClick={this.onAddressClick.bind(this)}>
                              <div>{getLabel('500931', "查看附近客户")}</div>
                              <div className="crm-field-item-operate"><Icon type={"right"} /></div>
                            </div>
                          } />
                        </Card>
                      </PullToRefresh>
                    </div>
                  )
                }
                {
                  tabPage == "contact" && (
                    <div className="crm-card-list">
                      <ContactList params={{ customerId: customerId }} onRef={this.onRef} showAddContact={showAddContact}></ContactList>
                    </div>
                  )
                }
                {
                  tabPage == "chance" && (
                    <div className="crm-card-list">
                      <ListViewPage.Normal
                        showCheck={false}
                        store={chanceListStore}
                        onRowClick={this.onChanceRowClick.bind(this)}
                      />
                    </div>
                  )
                }
             
              </div>
              <div className="crm-hide-area">
                <BrowserHrm
                  // label="人力单选"
                  store={managerBrowser}
                  hasAdvanceSerach
                  isSingle={true}
                  type={1}
                  onChange={(hrmId) => {
                    if (hrmId) {
                      alert('', getLabel('390935', '确定变更客户经理吗?'), [
                        { text: getLabel('201', '取消'), onPress: () => { } },
                        {
                          text: getLabel('83446', '确定'), onPress: () => {
                            store.changeManager(hrmId);
                          }
                        },
                      ]);
                    }
                  }}
                />
              </div>

              {/* 分享 */}
              <Route
                key={shareCustomerLayout.id}
                path={shareCustomerLayout.path}
                render={() => {
                  let shareDialog = 
                   <Share
                  
                        shareParams={ {
                          'resourcetype' : "7",
                          'resourceid' : customerId
                        }
                        }
                        store={shareStore }
                        msgInfo={{
                          'content': customerName, // 分享标题（必填）
                          'sysid': window.localStorage.emobile_ec_id, //EM中添加的集成系统的ID (必填: 按照demo给的传)             
                          //'desc': "客户啊啊啊", // 分享描述（非必填）
                          'linkurl':`/common/chatResource/view.html?resourcetype=7&resourceid=${customerId}&isfromchatshare=1&sharer=${userId}&firstSharer=${userId}&moduleid=em`,// 消息链接地址（必填） // 消息链接地址（必填）
                          //'linkurl_pc':"/viewrequest.jsp?id=123", //PC端消息链接地址，如果没有则取linkurl值
                          'canforward':1, // 消息是否允许转发 1：是（默认） 0：否
                          'callbackurl':"/api/common/chatResource/addshare?resourcetype=7&resourceid="+customerId+"&isfromchatshare=1&firstSharer="+userId, // 消息转发回调地址（非必填）
                          'sharetypename':getLabel(520328,"客户名片"), //消息类型显示标题，没有则按sharetype显示
                          'opentype':1, //移动端打开方式 1:app内打开（默认） 2：手机默认浏览器打开
                          'opentype_pc':2, //PC端打开方式 1:应用内打开（默认） 2：PC默认浏览器打开
                          'sharetype':"crm", // 分享数据类型："doc","workflow","task","pdoc","folder" ,"crm" 分别代表文档，流程，任务，云盘文档，云盘文件，客户名片
                          'shareid':customerId // 分享的数据ID（必填）
                        
                        } 
                      }                                                           
                   />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="shareCustomerLayout"
                        className="wm-route-layout"
                      >
                        {shareDialog}
                      </div>
                    </RouteLayout>
                  )
                }}
              />
              {/* end */}

              <Route
                key={customerMapLayout.id}
                path={customerMapLayout.path}
                render={() => {
                  let detailContent = <CustomerMap params={{ customerId: customerId }} />;
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="customerMapLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />
              <Route
                key={createContacterLayout.id}
                path={createContacterLayout.path}
                render={() => {
                  // 新建联系人
                  let detailContent = <ContacterForm cardStore={store} params={{ operation: "add", customerId: customerId }} />

                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="createContacterLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />
              <Route
                key={createChanceLayout.id}
                path={createChanceLayout.path}
                render={() => {
                  // 新建商机
                  let detailContent = <ChanceForm cardStore={store} params={{ operation: "add", customerid: customerId }} />

                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="createChanceLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />

              <Route
                key={contacterListLayout.id}
                path={contacterListLayout.path}
                render={() => {
                  // 查看全部联系人
                  let detailContent = <ContacterList params={store.params} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="contacterListLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />
              <Route
                key={workplanListLayout.id}
                path={workplanListLayout.path}
                render={() => {
                  // 查看全部联系计划
                  let detailContent = <WorkplanListSingle params={{ customerId: customerId }} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="workplanListLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />
              <Route
                key={contacterCardLayout.id}
                path={contacterCardLayout.path}
                render={() => {
                  // 联系人卡片
                  let detailContent = <ContacterCard params={{ id: curContacterId }} entryType="customerCard" cardStore={store} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="contacterCardLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />
              <RouteLayout.Frame
                id="wpViewLayout"
                path={commerceCardLayout.path}
                iframeProps={{
                  src: "/spa/crm/static/index.html#/main/crm/api/APIShowGroup/crmGroup?EtpFullName=" + customerName + "&keyword=" + customerName,
                }}
              />
              {/* <Route
                key={commerceCardLayout.id}
                path={commerceCardLayout.path}
                render={() => {
                  // 工商信息
                  let detailContent = <CommerceCard params={{ id: customerId }} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="commerceCardLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              /> */}
              <Route
                key={signInOutLayout.id}
                path={signInOutLayout.path}
                render={() => {
                  // 签到签退
                  let detailContent = <CustomerVisit cardStore={store} params={{ customerId: customerId, lat1:parseFloat(lat1), lng1: parseFloat(lng1) }} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="signInOutLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />
              <Route
                key={shareListLayout.id}
                path={shareListLayout.path}
                render={() => {
                  // 查看共享
                  let detailContent = <CustomerShareList params={{ id: customerId }} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="shareListLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />

              <Route
                key={changeLocalLayout.id}
                path={changeLocalLayout.path}
                render={() => {
                  // console.log(getUserPosition,hasPosition,lng1,lat1,userCurrentlat,userCurrentlng)
                  // 修改定位
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="changeLocalLayout"
                        className="wm-route-layout"
                      >
                        {(getUserPosition || hasPosition) && ((lng1 && lat1) || (parseInt(lat1) !== 0 && parseInt(lng1) !== 0) || (userCurrentlat && userCurrentlng)) ?
                          <div className="crm_map">
                          {(!hasPosition) ? Bubble.warning(getLabel('500811', '当前客户无定位信息，已为您定位至当前位置'), 5) : ""}
                          <div className="crm_map_title">
                            {customerName + "-" + getLabel('293', '更改') + getLabel('500359', '定位')}
                          </div>
                          <div className="crm_map_content_change">
                            <ChangePosition
                              lat1={(lat1&&parseInt(lat1) !== 0)?lat1: userCurrentlat}
                              lng1={(lng1&&parseInt(lng1) !== 0)?lng1: userCurrentlng}
                              onSubmit={this.getLocation}
                            />
                          </div>
                        </div> :
                          <div className="crm-bg-loading"><ActivityIndicator text={getLabel('385766', '定位中') + "..."} /></div>
                        }
                      </div>
                    </RouteLayout>
                  )
                }}
              />

              <Route
                key={chanceCardLayout.id}
                path={chanceCardLayout.path}
                render={() => {
                  // 商机卡片
                  let detailContent = <ChanceCard params={{ id: curChanceId }} cardStore={store} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="chanceCardLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />

              <Route
                key={crmDetailAndEditLayout.id}
                path={crmDetailAndEditLayout.path}
                render={() => {
                  // 客户卡片详细信息页面
                  const p = store.params;
                  p.name = customerName;
                  p.canEdit = canEdit;
                  p.isManager = isManager;
                  let detailContent = <CustomerViewAndEdit params={p} />
                  return (
                    <RouteLayout getContainer={() => document.getElementById("root")}>
                      <div
                        key="crmDetailAndEditLayout"
                        className="wm-route-layout"
                      >
                        {detailContent}
                      </div>
                    </RouteLayout>
                  )
                }}
              />

              <RouteLayout.Frame
                id="workplanCreateLayout"
                path={workplanCreateLayout.path}
                iframeProps={{
                  src: "/spa/workplan/static4mobile/index.html#/create?fromType=crm&workPlanTypeOptions=3&crmIDs=" + customerId,
                }}
              />

              <RouteLayout.Frame
                id="workplanViewLayout"
                path={workplanViewLayout.path}
                iframeProps={{
                  src: "/spa/workplan/static4mobile/index.html#/detail?fromType=crm&workplanId=" + curWorkplanId,
                }}
              />
            </div>
          );
        } else {
          return <NoRight />
        }
      } else {
        return (
          <div>
            <CrmResult
              message={initFailedMsg}
            />
          </div>);
      }
    } else {
      return <div className="crm-bg-loading"><ActivityIndicator text="Loading..." /></div>;
    }
  }
  onRef = (ref) => {
    this.contactListRef = ref;
  }
  // 客户信息操作
  iconClick(itemKey, title, value, valueSpan) {
    // const store = this.props.customerCardStore;
    const store = this.state.store;
    const { customerMapLayout, customerId, commerceCardLayout, changeLocalLayout, hasPosition, getUserPosition, tabPage, getUserCurrentPosition } = store;
    if (itemKey === 1) {
      this.props.history.push(commerceCardLayout.path);
    }
    if (itemKey === 2) {
      // 修改经理
      const { managerBrowser } = store;
      this.props.history.push(managerBrowser.path);
    } else if (itemKey === "address") {
      // 定位
      //如果没有定位信息，则在进入页面之后获取位置信息
      if (!hasPosition) {
        getUserCurrentPosition();
        this.props.history.push(changeLocalLayout.path);
      } else {
        this.props.history.push(changeLocalLayout.path);
      }
    }
  }

  contentClick(itemKey, value, valueSpan) {

    if (itemKey === 2) {
      // console.log(itemKey,value,valueSpan);
      window.openLink.openHrm(value);
    }
  }

  // 关注 or 取消关注
  concernedClick(concerned) {
    // const store = this.props.customerCardStore;
    const store = this.state.store;
    store.setCustomerConcerned(concerned);
  }

  //查看附近客户
  onAddressClick() {
    const { customerMapLayout, hasPosition, canEdit, changeLocalLayout, getUserCurrentPosition } = this.state.store;
    if (!hasPosition) {
      if (canEdit) {
        alert('', getLabel('500807', '请先维护客户地址信息！是否前往更改定位?'), [
          {
            text: getLabel('201', '取消'), onPress: () => {
              this.setState({ headLeadClick: false })
            }
          },
          {
            text: getLabel('83446', '确定'), onPress: () => {
              getUserCurrentPosition();
              this.props.history.push(changeLocalLayout.path);
            }
          }
        ]);
      } else {
        alert('', getLabel('500808', '尚无该客户位置信息'), [
          {
            text: getLabel('83446', '确定'), onPress: () => {
            }
          },
        ]);
      }
    } else {
      this.props.history.push(customerMapLayout.path);
    }
  }

  onContacterClick(id) {
    // const store = this.props.customerCardStore;
    this.setState({ curContacterId: id });
    const store = this.state.store;
    const { contacterCardLayout } = store;
    this.props.history.push(contacterCardLayout.path);
  }

  onPlanItemClick(id) {
    // const store = this.props.customerCardStore;
    const { workplanViewLayout } = this.state.store;
    this.setState({ curWorkplanId: id });
    this.props.history.push(workplanViewLayout.path);
  }

  onChanceRowClick(rowData) {
    this.setState({ curChanceId: rowData.id });
    const store = this.state.store;
    const { chanceCardLayout } = store;
    this.props.history.push(chanceCardLayout.path);
  }

  moreClick() {
    // const store = this.props.customerCardStore;
    const store = this.state.store;
    const { canEdit, doDelete, managerBrowser, customerId, fixedPosition, createChanceLayout, signInOutLayout, 
      shareListLayout, changeLocalLayout, tabPage, isManager,canShare,shareCustomerLayout ,onlyView} = store;
    let btns = [];

    btns.push({ key: 1, content: getLabel('390921', "添加联系记录") });
    btns.push({ key: 2, content: getLabel('20032', '签到') + '、' + getLabel('20033', '签退') });
    if (canEdit) {
      btns.push({ key: 3, content: getLabel('124910', '新建商机') });
    }
    if (isManager) {
      btns.push({ key: 4, content: getLabel('501292', '删除客户') });
    }
    btns.push({ key: 5, content: getLabel('30832', '查看共享') });
    if(canShare){
      btns.push({ key: 7, content: getLabel('126091', '分享') });
    }

    btns.push({ key: 6, content: getLabel('201', '取消') });
  

    ActionSheet.showActionSheetWithOptions({
      options: btns,
      cancelButtonIndex: btns.length - 1,
      maskClosable: true,
      'data-seed': 'logId',
      wrapProps,
    },
      (buttonIndex) => {
        let btn = btns[buttonIndex];
        if (btn.key === 1) {
          if (tabPage == "contact") {
            this.contactListRef.addContact();
          } else {
            store.tabChange("contact");
            this.setState({ showAddContact: true });
            setTimeout(() => {
              this.setState({ showAddContact: false });
            }, 100);
          }
        } else if (btn.key === 2) {
          this.props.history.push(signInOutLayout.path);
        } else if (btn.key === 3) {
          this.props.history.push(createChanceLayout.path);
        } else if (btn.key === 4) {
          alert('', getLabel('83600', '您确认要删除吗？'), [
            { text: getLabel('201', '取消'), onPress: () => { } },
            { text: getLabel('83446', '确定'), onPress: () => { doDelete(); } },
          ]);
        } else if (btn.key === 5) {
          this.props.history.push(shareListLayout.path);
        }else if(btn.key  === 7){ 
            this.props.history.push(shareCustomerLayout.path);
        }
        
      });
  }

  getLocation = (data) => {
    const { customerAddress, changeAddress } = this.state.store;
    let address = data.pname + data.cityname + data.adname + data.address + data.name;
    if (data.pname === data.cityname) {
      address = data.cityname + data.adname + data.address + data.name;
    }
    // changePositionSpan(data);
    if (customerAddress !== address) {
      alert('', getLabel('500933', '是否确认修改定位信息？'), [
        {
          text: getLabel('201', '取消'), onPress: () => {
            this.props.history.go(-1);
          }
        },
        {
          text: getLabel('83446', '确定'), onPress: () => {
            changeAddress(data);
            this.props.history.go(-1);
          }
        }
      ])
    } else {
      this.props.history.go(-1);
    }
  }
}